﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyDuAn.BUS;
using QuanLyDuAn.Report;
using System.Collections;

namespace QuanLyDuAn.GUI
{
    public partial class FrmSearchInterviewPlan : DevComponents.DotNetBar.Office2007Form
    {
        public String value;
        InterviewPlanController plan = new InterviewPlanController();
        InterviewerController interviewer = new InterviewerController();
        DataSet dsInterview;
        ArrayList list;
        public FrmSearchInterviewPlan()
        {
            InitializeComponent();
        }

        private void FrmSearchInterviewPlan_Load(object sender, EventArgs e)
        {
            this.dataGridViewX1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dsInterview = interviewer.LoadInterviewer();
            cmbInterviewer.DataSource = dsInterview.Tables[0];
            cmbInterviewer.DisplayMember = dsInterview.Tables[0].Columns[3].ToString();
            cmbInterviewer.ValueMember = dsInterview.Tables[0].Columns[0].ToString();
            cmbInterviewer.Enabled = false;
            dtDate.Enabled = false;
            rdDone.Enabled = false;
            rdInprogess.Enabled = false;
            rdWait.Enabled = false;
            cmbCriterion.Items.Add("Interviewer Name");
            cmbCriterion.Items.Add("Interview in Date");
            cmbCriterion.Items.Add("Status");
            LoadDataToCollection();
        }
        public void CriterionChange()
        {
            String criterion = cmbCriterion.SelectedItem.ToString();
            if (criterion.CompareTo("Status") == 0)
            {
                MessageBox.Show("Please Select Status of Interview !");
                dtDate.Enabled = false;
                cmbInterviewer.Enabled = false;
                rdDone.Enabled = true;
                rdInprogess.Enabled = true;
                rdWait.Enabled = true;
            }
            else if (criterion.CompareTo("Interview in Date") == 0)
            {
                MessageBox.Show("Please Select Date !");
                dtDate.Enabled = true;
                rdDone.Enabled = false;
                rdInprogess.Enabled = false;
                rdWait.Enabled = false;
                cmbInterviewer.Enabled = false;
            }
            else
            {
                MessageBox.Show("Please Select Interviewer Name !");
                dtDate.Enabled = false;
                rdDone.Enabled = false;
                rdInprogess.Enabled = false;
                rdWait.Enabled = false;
                cmbInterviewer.Enabled = true;
            }
        }
        public int ValueCriterrion()
        {
            int selection;
            String criter = cmbCriterion.Text;
            if (criter.CompareTo("") != 0)
            {
                String criterion = cmbCriterion.SelectedItem.ToString();
                if (criterion.CompareTo("Status") == 0)
                {
                    selection = 1;
                }
                else if (criterion.CompareTo("Interviewer Name") == 0)
                {
                    selection = 2;
                }
                else
                {
                    selection = 3;
                }
            }
            else
            {
                selection = 0;
                MessageBox.Show("Please select Criterion !");
            }
            return selection;
        }
        private void cmbCriterion_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.CriterionChange();
        }
        public String GetStatus()
        {
            String status;
            if (rdInprogess.Checked == true)
            {
                status = "Inprogess";
            }
            else if (rdDone.Checked == true)
            {
                status = "Done";
            }
            else
            {
                status = "Wait";
            }
            return status;
        }
        public void SearchByInterviewer()
        {
            String interviewer = cmbInterviewer.SelectedValue.ToString();
            dsInterview = new DataSet();
            dsInterview = plan.SearchPlanByInterviewer(interviewer);
            dataGridViewX1.DataSource = dsInterview.Tables[0];
        }
        public void SearchByDate()
        {
            DateTime date = dtDate.Value;
            dsInterview = new DataSet();
            dsInterview = plan.SearchPlanByDate(date);
            dataGridViewX1.DataSource = dsInterview.Tables[0];
        }
        public void SearchByStatus()
        {
            String status = this.GetStatus();
            dsInterview = new DataSet();
            dsInterview = plan.SearchPlanByStatus(status);
            dataGridViewX1.DataSource = dsInterview.Tables[0];
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            int i = this.ValueCriterrion();
            if (i == 2)
            {
                this.SearchByInterviewer();
            }
            else if (i == 1)
            {
                this.SearchByStatus();
            }
            if (i == 3)
            {
                this.SearchByDate();
            }
        }

        public void LoadDataToCollection()
        {
            AutoCompleteStringCollection autoString = new AutoCompleteStringCollection();
            list = new ArrayList();
            list = interviewer.GetInterviewerName();
            foreach (String Name in list)
            {
                autoString.Add(Name);
            }
            cmbInterviewer.AutoCompleteMode = AutoCompleteMode.Append;
            cmbInterviewer.AutoCompleteSource = AutoCompleteSource.CustomSource;
            cmbInterviewer.AutoCompleteCustomSource = autoString;
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            String interviewer = cmbInterviewer.Text;
            DateTime date = dtDate.Value;
            String status = this.GetStatus();
            int i = this.ValueCriterrion();
            if (i == 2)
            {
                FrmPlanInterviewer frmPlan = new FrmPlanInterviewer();
                frmPlan.value = interviewer;
                frmPlan.Visible = true;
                frmPlan.Show();
            }
            else if (i == 1)
            {
                FrmInterviewPlanStatus frm = new FrmInterviewPlanStatus();
                frm.value = status;
                frm.Visible = true;
                frm.Show();
            }
            else if (i == 3)
            {
                FrmInterviewPlanDate frm = new FrmInterviewPlanDate();
                frm.value = date;
                frm.Visible = true;
                frm.Show();
            }
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            DateTime nowdate = DateTime.Today;
            FrmInterviewPlanToday frm = new FrmInterviewPlanToday();
            frm.value = nowdate;
            frm.Visible = true;
            frm.Show();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void dataGridViewX1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

       

    }
}
